package com.k2data.test.parameterized;

import org.junit.jupiter.api.extension.ParameterContext;
import org.junit.jupiter.params.converter.ArgumentConversionException;
import org.junit.jupiter.params.converter.ArgumentConverter;

/**
 * 
 * @author wangchuan 2019-01-28
 *
 */
public class PointConverter implements ArgumentConverter{

	@Override
	public Object convert(Object arg0, ParameterContext arg1) throws ArgumentConversionException {
		if (arg0 instanceof Point)
			return arg0;
		if (arg0 instanceof String)
			try {
				return Point.from((String) arg0);
			} catch (NumberFormatException ex) {
				String message = arg0 + " is no correct string representation of a point.";
				throw new ArgumentConversionException(message, ex);
			}
		return null;
	}
}
